//
//  UIImage+Extension.swift
//  CMDB
//
//  Created by 曹桂祥 on 17/4/21.
//  Copyright © 2017年 CMDB. All rights reserved.
//

import UIKit

extension UIImage{
    
    //保存图片路径
    class func getImagePath(image: UIImage? ,imageName: String?) -> String? {
        guard let _ = image else {
            return nil
        }
        let data = UIImageJPEGRepresentation(image!, 0.1)
        
        let documentsPath = (NSHomeDirectory() as NSString).stringByAppendingPathComponent("Documents")
        
        let fm = NSFileManager.defaultManager()
        
        try! fm.createDirectoryAtPath(documentsPath, withIntermediateDirectories:  true, attributes: nil)
        
        let imagePath = "/\(imageName!)"
        
        fm.createFileAtPath("\(documentsPath)\(imagePath)", contents: data, attributes: nil)
        
        return "\(documentsPath)\(imagePath)"
    }
    
    //从图片路径删除
    class func removeImageAtPath(imageName: String?) {
        let documentsPath = (NSHomeDirectory() as NSString).stringByAppendingPathComponent("Documents")
        
        let fm = NSFileManager.defaultManager()
        
        let filePath = "\(documentsPath)/\(imageName!)"
        
        try! fm.removeItemAtPath(filePath)
    }
    
}

//MARK:- 图片生成
extension UIImage{


}
